<template>
  <div id="login">
    <el-form :label-position="labelPosition" :rules="rules" ref="loginForm" :model="loginForm">
      <div class="title">
        <span>登录</span>
      </div>
      <el-form-item prop="account">
        <el-input v-model="loginForm.account" placeholder="输入你的账号"></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input v-model="loginForm.password" placeholder="输入你的密码" type="password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button class="loginBtn1" type="primary" @click="submitForm()">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  name: "login",

  data() {
    var validateAccount = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入账号"));
      } else {
        if (this.loginForm.checkAccount !== "") {
          this.$refs.loginForm.validateField("checkAccount");
        }
        callback();
      }
    };
    var validatePassword = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.loginForm.checkPassord !== "") {
          this.$refs.loginForm.validateField("checkPassword");
        }
        callback();
      }
    };
    return {
      labelPosition: "left",
      loginForm: {
        account: "",
        password: ""
      },
      rules: {
        account: [{ validator: validateAccount, trigger: "blur" }],
        password: [{ validator: validatePassword, trigger: "blur" }]
      },
      loginForm: {
        adminInfo: "",
        adminPwd: ""
      }
    };
  },
  methods: {
    submitForm() {
      this.$post_form(this.$urlPath.user + "/admin/Login", {
        adminInfo: this.loginForm.account,
        adminPwd: this.loginForm.password
      }).then(resp => {
        if (resp.code != 200) {
          return this.$message.error(resp.message);
        }

        window.localStorage.setItem("cicToken", resp.map.cicToken);
        this.$router.push({ path: "/index" });
      });
    }
  }
};
</script>
<style lang="less">
@import "../assets/less/login.less";
</style>